package com.sbx.controller;


import com.sbx.entity.dto.AppDock;
import com.sbx.service.AppDockService;
import com.sbx.utils.Result;
import com.sbx.validations.RequiredField;
import com.sbx.validations.NotRequiredField;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/appDock")
@Api(tags = "程序坞管理")
public class AppDockController {

    @Resource
    private AppDockService appDockService;

    /**
     * 新增
     */
    @PostMapping
    @ApiOperation("新增程序")
    public Result insert(@RequestBody @Validated(value = RequiredField.class) AppDock appDock) {
        appDockService.insert(appDock);
        return Result.success();
    }

    @ApiOperation("删除程序坞")
    @DeleteMapping("{id}")

    public Result deleteById(@PathVariable @ApiParam("程序坞id") Integer id) {
        appDockService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询程序坞")

    public Result getAppDockPage(@Validated(value = NotRequiredField.class) AppDock appDock,
                                 @ApiParam("起始页") @RequestParam(defaultValue = "1") Integer pageIndex,
                                 @ApiParam("每页条数") @RequestParam(defaultValue = "10") Integer pageSize) {

        return Result.page(appDockService.getAppDockPage(appDock, pageIndex, pageSize));
    }

    @PutMapping
    @ApiOperation("用户信息修改")
    public Result update(@RequestBody @Validated(NotRequiredField.class) AppDock appDock) {
        appDockService.update(appDock);
        return Result.success();
    }


}
